#!/usr/bin/env python
# -*- coding: utf-8 -*-

import queue
import time
import sys
import datetime
import os, configparser

sys.path.append('classes')

from WSBase import WSBase
from Registry import Registry
from pymongo import MongoClient
from Common import Common
import argparse



def main():

	base = WSBase()
	parser = argparse.ArgumentParser(description='Web-Scout')
	parser.add_argument("module", help="module")
	args = parser.parse_args(sys.argv[1:2])
	if(args.module):
		print("Started module work at " + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
		module = base.loadModule(args.module)
		parser = argparse.ArgumentParser(description=module.help(),
										prog=sys.argv[0]+" "+args.module)
		for option in module.options:
			parser.add_argument(*module.options[option].flags, required=module.options[option].required, 
				help=module.options[option].description, dest=module.options[option].name)
		args = vars(parser.parse_args(sys.argv[2:]))
		for option in args.keys():
			if not(args[option] is None): module.options[option].value=args[option]
		module.run()
		while not module.finished():
			try:
				sys.stdout.flush()
			except:
				time.sleep(1)
		print("\nEnded module work at " + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
		print("\n" + module.getResult());
if __name__ == '__main__':
	main()

